
//
//  StatusCellTopView.swift
//  WeiBo09
//
//  Created by 裘明 on 15/9/12.
//  Copyright © 2015年 qm. All rights reserved.
//

import UIKit
import SDWebImage

let MQStatusCellMargin:CGFloat = 15
let MQStatusIconWidth: CGFloat = 35

/// 微博顶部视图
class StatusCellTopView: UIView {
    
    /// 微博视图模型
    var statusViewModel: StatusViewModel? {
        didSet {
            // 设置界面数据
            iconView.sd_setImageWithURL(statusViewModel?.userIconUrl)
            nameLabel.text = statusViewModel?.userName
            vipView.image = statusViewModel?.userVipImage
            memberView.image = statusViewModel?.userMemberImage
            // TODO: 还有两没有设置
        }
    }
    
    // - MARK: - 搭建界面
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        setupUI()
    }

    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
        setupUI()
    }
    
    /// 设置界面
    func setupUI() {
        backgroundColor = UIColor.whiteColor()
        // 1.添加控件
        addSubview(iconView)
        addSubview(nameLabel)
        addSubview(memberView)
        addSubview(vipView)
        addSubview(timeLabel)
        addSubview(sourceLabel)
        
        // 2.设置约束
        let offset: CGPoint = CGPoint(x: MQStatusCellMargin, y: 0)
        iconView.ff_AlignInner(type: ff_AlignType.TopLeft, referView: self, size: CGSize(width: MQStatusIconWidth, height: MQStatusIconWidth), offset: CGPoint(x: MQStatusCellMargin, y: MQStatusCellMargin))
        nameLabel.ff_AlignHorizontal(type: ff_AlignType.TopRight, referView: iconView, size: nil, offset: offset)
        memberView.ff_AlignHorizontal(type: ff_AlignType.TopRight, referView: nameLabel, size: nil, offset: offset)
        vipView.ff_AlignInner(type: ff_AlignType.BottomRight, referView: iconView, size: nil, offset: CGPoint(x: 8, y: 8))
        timeLabel.ff_AlignHorizontal(type: ff_AlignType.BottomRight, referView: iconView, size: nil, offset:offset)
        sourceLabel.ff_AlignHorizontal(type: ff_AlignType.TopRight, referView: timeLabel, size: nil, offset: offset)
    }
    
    // MARK: - 懒加载控件
    /// 头像
    private lazy var iconView: UIImageView = {
       
        let icon = UIImageView()
        icon.layer.cornerRadius = 5
        icon.layer.masksToBounds = true
        icon.image = UIImage(named: "avatar_default_big")
        
        return icon
        }()
    /// 名称
    private lazy var nameLabel: UILabel = UILabel(title: "姓名", color: UIColor.darkGrayColor(), fontSize: 14)
    /// 会员
    private lazy var memberView: UIImageView = UIImageView(image: UIImage(named: "common_icon_membership_level1"))
    /// VIP
    private lazy var vipView: UIImageView = UIImageView(image: UIImage(named: "avatar_grassroot"))
    /// 时间
    private lazy var timeLabel: UILabel = UILabel(title: "刚刚", color: UIColor.orangeColor(), fontSize: 10)
    /// 来源
    private lazy var sourceLabel:UILabel = UILabel(title: "来自 新浪微博", color: UIColor.darkGrayColor(), fontSize: 10)
    
    
    
}
